import { PcSeriveProvider } from './../../../providers/pc-serive/pc-serive';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

/**
 * Generated class for the PcReportPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-pc-report',
  templateUrl: 'pc-report.html',
})
export class PcReportPage {
  teamshow = [];//显示团队已经结束的评测 
  goodshow = [];//显示优秀成员
  evalteam = [];//显示团队所有评测
  data = { 
    evaluatingcode:null,
    teamcode:null,
  };
  constructor(public navCtrl: NavController, public navParams: NavParams, private pcSerive: PcSeriveProvider) {
    this.data.teamcode = this.navParams.get("teamCode"); 
    this.data.evaluatingcode = this.navParams.get("evalcode");
    this.pcSerive.getTeam(this.data).subscribe(data => {

      this.evalteam = data['evaluatingList'];
      this.goodshow = data['evaluateScoreList'];
      this.teamtate();

      let teamimg = JSON.parse(localStorage.getItem('teamimg'));
      for (let i = 0; i < this.evalteam.length; i++) {
        for (let index = 0; index < teamimg.length; index++) {
          if (teamimg[index]['teamcode'] == this.data.teamcode) {
            this.evalteam[i]['imgs'] = this.pcSerive.imgdate[teamimg[index]['teambg']]['img'];
          }
        }
      }
    });
  }
   
 //判断评测是否开启
  teamtate() { 
    for (let i = 0; i < this.evalteam.length; i++) {
      let tday = new Date();
      let eday = new Date(this.evalteam[i]["evaluatingendtime"]);//结束天
      eday.setHours(23,59,59); 
      if (tday.valueOf()>eday.valueOf()) { 
        this.teamshow.push(this.evalteam[i])
      }        
    }
  }
 
  //跳转优秀成员
  openMyRp(id){     
    this.navCtrl.push('PcMyreportPage',{  
      userid: id,  //传userid
      evalcode:this.data.evaluatingcode, //传评测编号 
      evalDatas: this.goodshow     
    })  
  }

  //跳转团队报告
  openTeamRp(id) {
    this.navCtrl.push('PcTeamReportPage', {
      evalDatas: this.goodshow,     
      evalcode: this.teamshow[id]['evaluatingcode'],
      evalpj: this.teamshow[id]['evaluatingproject'],
    })
  }



}
